package com.netease.evo.service.impl;

import com.netease.evo.dto.CourseDto;
import com.netease.evo.dto.UserDto;
import com.netease.evo.dto.UserQueryDto;
import com.netease.evo.enums.UserTypeEnum;
import com.netease.evo.service.CourseService;
import com.netease.evo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Package: com.netease.evo.service.impl
 * @Description: java类作用描述
 * @Author: rayduan
 * @CreateDate: 2021/11/23 4:52 下午
 * @Version: 1.0
 * <p>
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private CourseService courseService;
    /**
     * 根据id获取用户信息
     *
     * @param id
     * @return
     */
    @Override
    public UserDto getUserById(Integer id) {
        UserDto user = null;
        switch (id) {
            case 1: {
                user = UserDto.builder().id(1).username("张三").age(18).email("324234@qq.com").build();
                break;
            }
            case 2: {
                user = UserDto.builder().id(2).username("王五").age(19).email("324234@qq.com").build();
                break;
            }
            default:
        }
        return user;
    }

    @Override
    public List<UserDto> queryUser(UserQueryDto query) {
        UserDto user = null;
        Integer type = query.getType();
        UserTypeEnum userTypeEnum = UserTypeEnum.getByCode(type);
        switch (userTypeEnum) {
            case STUDENT: {
                user = UserDto.builder().id(1).username("李四").age(18).email("324234@qq.com").build();
                break;
            }
            case TEACHER:  {
                user = UserDto.builder().id(3).username("黑皮").age(19).email("324234@qq.com").build();
                break;
            }
            default:
        }
        return Stream.of(user).collect(Collectors.toList());
    }

    @Override
    public List<CourseDto> getCourseById(Integer id) {
        List<CourseDto> courseList = courseService.getByUserId(id);
        return courseList.stream().filter(e -> "语文".equals(e.getName())).collect(Collectors.toList());
    }
}
